package com.j2eefast.flowable.bpm.service;


import cn.hutool.core.util.IdUtil;
import com.j2eefast.flowable.bpm.entity.bpmCrmBackcarEntity;
import com.j2eefast.flowable.bpm.mapper.bpmCrmBackcarMapper;
import com.j2eefast.common.core.mutidatasource.annotaion.DataSource;
import com.j2eefast.common.core.page.Query;
import com.j2eefast.common.core.utils.PageUtil;
import com.j2eefast.common.core.utils.ToolUtil;
import com.j2eefast.framework.utils.Constant;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import javax.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;
import java.util.Map;
import java.util.Arrays;
/**
 *
 * 退车Service接口
 * @author: yhli
 * @date 2020-06-28 20:42
 */
@Service
public class bpmCrmBackcarService extends ServiceImpl<bpmCrmBackcarMapper,bpmCrmBackcarEntity> {

	@Resource
	private bpmCrmBackcarMapper bpmCrmBackcarMapper;

	/**
	 * mybaitis-plus 页面分页查询
     */
    @DataSource(name="FLOWABLE")
	public PageUtil findPage(Map<String, Object> params) {
        QueryWrapper<bpmCrmBackcarEntity> queryWrapper = new QueryWrapper<bpmCrmBackcarEntity>();
              String saleCode = (String) params.get("saleCode");
         queryWrapper.eq(ToolUtil.isNotEmpty(saleCode), "sale_code", saleCode);
                               String saleUserid = (String) params.get("saleUserid");
         queryWrapper.eq(ToolUtil.isNotEmpty(saleUserid), "sale_userid", saleUserid);
          String saleOrderNumber = (String) params.get("saleOrderNumber");
         queryWrapper.eq(ToolUtil.isNotEmpty(saleOrderNumber), "sale_order_number", saleOrderNumber);
          String outCarVin = (String) params.get("outCarVin");
         queryWrapper.eq(ToolUtil.isNotEmpty(outCarVin), "out_car_vin", outCarVin);
          String outCarVehicle = (String) params.get("outCarVehicle");
         queryWrapper.eq(ToolUtil.isNotEmpty(outCarVehicle), "out_car_vehicle", outCarVehicle);
             String salesDirectorReview = (String) params.get("salesDirectorReview");
         queryWrapper.eq(ToolUtil.isNotEmpty(salesDirectorReview), "sales_director_review", salesDirectorReview);
             String warehouseInventoryReview = (String) params.get("warehouseInventoryReview");
         queryWrapper.eq(ToolUtil.isNotEmpty(warehouseInventoryReview), "warehouse_inventory_review", warehouseInventoryReview);
             String warehouseAppraisalAmount = (String) params.get("warehouseAppraisalAmount");
         queryWrapper.eq(ToolUtil.isNotEmpty(warehouseAppraisalAmount), "warehouse_appraisal_amount", warehouseAppraisalAmount);
          String warehouseReturnCost = (String) params.get("warehouseReturnCost");
         queryWrapper.eq(ToolUtil.isNotEmpty(warehouseReturnCost), "warehouse_return_cost", warehouseReturnCost);
          String salesDirectorFinalReview = (String) params.get("salesDirectorFinalReview");
         queryWrapper.eq(ToolUtil.isNotEmpty(salesDirectorFinalReview), "sales_director_final_review", salesDirectorFinalReview);
          String salesDirectorFinalMemo = (String) params.get("salesDirectorFinalMemo");
         queryWrapper.eq(ToolUtil.isNotEmpty(salesDirectorFinalMemo), "sales_director_final_memo", salesDirectorFinalMemo);
  		Page<bpmCrmBackcarEntity> page = bpmCrmBackcarMapper.selectPage(new Query<bpmCrmBackcarEntity>(params).getPage(), queryWrapper);
		return new PageUtil(page);
    }

    /**
     * 自定义分页查询，含关联实体对像
     */
    @DataSource(name="FLOWABLE")
	public PageUtil findPage(Map<String, Object> params,bpmCrmBackcarEntity bpmCrmBackcarEntity) {
		Page<bpmCrmBackcarEntity> page = bpmCrmBackcarMapper.findPage(new Query<bpmCrmBackcarEntity>(params).getPage(), bpmCrmBackcarEntity,(String) params.get(Constant.SQL_FILTER))  ;
		return new PageUtil(page);
	}
	/**
     * 批量删除
     */
    @DataSource(name="FLOWABLE")
	@Transactional(rollbackFor = Exception.class)
	public boolean deletebpmCrmBackcarByIds(String[] ids) {
		return removeByIds(Arrays.asList(ids));
	}

	/**
     * 单个删除
     */
    @DataSource(name="FLOWABLE")
	public boolean deletebpmCrmBackcarById(String id) {
		return removeById(id);
	}

	/**
     * 保存
     */
    @DataSource(name="FLOWABLE")
	public boolean savebpmCrmBackcar(bpmCrmBackcarEntity bpmCrmBackcar){
        bpmCrmBackcar.setId(IdUtil.fastSimpleUUID());
        return save(bpmCrmBackcar);
    }

	/**
     * 修改根居ID
     */
    @DataSource(name="FLOWABLE")
	public boolean updatebpmCrmBackcarById(bpmCrmBackcarEntity bpmCrmBackcar) {
		return updateById(bpmCrmBackcar);
	}

	/**
     * 根居ID获取对象
     */
    @DataSource(name="FLOWABLE")
	public bpmCrmBackcarEntity getbpmCrmBackcarById(String id){
		return getById(id);
	}
}
